﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using BLL.Entities.Company;
using BLL.Entities;

namespace HTAProDataImporter.Transport
{
    public class CompanyTransport : BaseEntityTransport
    {
        public override string CommandText
        {
            get { return "select * from tblAgentCompany"; }
        }
        
        public override void InstanceFromReader(OleDbDataReader DR)
        {
            CompanyInfo company = CompanyAgent.CreateNewInstance<CompanyInfo>();

            company.Name = DR["CompanyName"].ToString();
            company.LegalName = DR["CompanyLegalName"].ToString();


            CompanyOffice office = CompanyOffice.CreateNewInstance<CompanyOffice>();
            office.CompanyID = company.EntityID;


            office.Address.AddressLine= DR["Address"].ToString();
            if(!string.IsNullOrEmpty(DR["Address2"].ToString()))
                office.Address.AddressLine = string.Format("{0}, {1}", office.Address.AddressLine, DR["Address2"].ToString());
            
            office.Address.City = DR["City"].ToString();
            office.Address.Province = DR["Province"].ToString();
            office.Address.PostalCode = DR["Postal"].ToString();


            office.Contact.Email = DR["Email"].ToString();
            office.Contact.Fax = DR["Fax"].ToString();
            office.Contact.PhoneWork = DR["Phone"].ToString();


            company.Offices.Add(office);

            DataStore.Companies.Add(DR["pkCompanyID"].ToString(), company);
        }
    }
}
